package Dao;

import java.sql.*;

import Entity.*;
import Util.*;

public class AddPayProveDao {
    //存入预付款存入凭证
    public void add(PayProveEntity pay) {
        try {
            //建立连接
            Connection conn = JdbcUtil.getConnection();
            //insert into pay(num,name,time,total,surplus,operator) values('61021','张根群','2015-09-08 09:51','50000','1000','郑斌');
            String sql = "insert into pay(num,name,code,time,pay_total,surplus,operator,project,nullify) values('" + pay.getNum() + "','" + pay.getName() + "','" + pay.getCode() + "','" + pay.getTime() + "','" + pay.getPay_total() + "','" + pay.getSurplus() + "','" + pay.getOperator() + "','" + pay.getProject() + "',0);";
            //创建语句
            PreparedStatement pstmt = conn.prepareStatement(sql);
            //执行语句
            pstmt.executeUpdate();
            JdbcUtil.close(pstmt, conn);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    //获得num的值
    public int select_num() {
        int num = 0;
        String sql = "select MAX(num) FROM pay;";
        try {
            Connection conn = JdbcUtil.getConnection();
            PreparedStatement pstmt = conn.prepareStatement(sql);
            //
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                num = rs.getInt(1);
            }
            JdbcUtil.close(pstmt, conn);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return num;
    }
}

